<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Reply as ModelReply;

/**
 * 意见反馈
 */
class Reply extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];



    /**
     * 提交
     *
     * @Author xy
     * @ApiMethod (POST)
     * @ApiParams (name="msg", type="str", required=true, sample="", description="意见")
     * @ApiParams (name="images", type="str", required=true, sample="", description="多图逗号分隔")
     * 
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':0,'msg':'返回成功'})
     */
    public function add()
    {
        $user = $this->auth->getUser();
        $res = new ModelReply();
        $res->save([
            'user_id' => $user['id'],
            'msg' => $this->request->post('msg'),
            'images' => $this->request->post('images'),
            'acct_id' => $user->acct_id,
        ]);
        $this->responseMsg(0);
    }


    /**
     * 我的列表
     * @Author xy
     * @ApiMethod (POST)
     * @ApiParams (name="status", type="integer", required=true, sample="", description="状态:''=全部,0=反馈中,1=已处理")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':0,'msg':'返回成功'})
     */
    function list()
    {
        $user = $this->auth->getUser();
        if ($this->request->post('status') !== '') {
            $list = ModelReply::where('user_id', $user->id)->where('status', (string)$this->request->post('status'))->order('id desc')->select();
        } else {
            $list = ModelReply::where('user_id', $user->id)->order('id desc')->select();
        }
        $this->responseMsg(0, $list);
    }
}
